﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 职工端
{
    public partial class 购货清单 : Form
    {
        DataSet myst = new DataSet();
        SqlDataAdapter myda;
        public 购货清单()
        {
            InitializeComponent();
        }

        private void btn_wc_Click(object sender, EventArgs e)
        {
            wid();
            清单 清单 = new 清单();
            this.Close();
            清单.Show();
        }
        void wid()
        {
            清单.wid = tbx_wid.Text;
        }
        private void btn_add_Click(object sender, EventArgs e)
        {
            SqlConnection sqlcon = new SqlConnection(denglu.strcon);
            try
            {
            sqlcon.Open();
                string wodate= DateTime.Now.ToLocalTime().ToString(); //获取当前时间
                string sql = "insert into Worder(wid,gid,sid,wodate,woammount) values('"+tbx_wid.Text+"','"+tbx_gid.Text+"','"+tbx_sid.Text+"','"+wodate+"','"+tbx_amount.Text+"')";
                SqlCommand cmd = new SqlCommand(sql,sqlcon);
                cmd.ExecuteNonQuery();
                MessageBox.Show("添加成功！");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString() + "加入失败！请检查后再加入清单");
            }
            finally
            {
                sqlcon.Close();
            }



        }

        private void btn_select_Click(object sender, EventArgs e)
        {
            if (int.Parse(tbx_num.Text)>0&&int.Parse(tbx_num.Text)<=999999)
            {
            SqlConnection sqlcon = new SqlConnection(denglu.strcon);
                sqlcon.Open();
                string sql = "select * from Goods where gammount<="+int.Parse(tbx_num.Text);
                SqlCommand cmd = new SqlCommand(sql, sqlcon);
                myda = new SqlDataAdapter(cmd);
                myst.Tables.Clear();
                myda.Fill(myst, "B");
                dataGridView1.DataSource = myst.Tables["B"];

                sqlcon.Close();
            }
            else
            {
                MessageBox.Show("请输入数字！","提示");
                return;
            }


        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection sqlcon = new SqlConnection(denglu.strcon);
            sqlcon.Open();
            string sql = "select * from Goods ";
            SqlCommand cmd = new SqlCommand(sql, sqlcon);
            myda = new SqlDataAdapter(cmd);
            myst.Tables.Clear();
            myda.Fill(myst, "B");
            dataGridView1.DataSource = myst.Tables["B"];
            sqlcon.Close();
        }
    }
}
